#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 10

typedef int ElemType;
typedef struct SeqList{
	ElemType * elem;
	int length;
	int size;
}SeqList,ListPtr;

void InitSeqList(SeqList * list);
void SeqListReverse_1(SeqList * list);
void SeqListReverse_2(SeqList * list);
void SeqListReverse_3(SeqList * list);
void ListDisplay(SeqList * list);

int main(){
	SeqList list;
	InitSeqList(&list);
	for(int i=0;i<list.size;i++){
		list.elem[i]=i;
		list.length++;
	}
	printf("原始的序列：");
	ListDisplay(&list);

	SeqListReverse_1(&list);
	printf("交换第一次后的序列：");
	ListDisplay(&list);

	SeqListReverse_2(&list);
	printf("交换第二次后的序列：");
	ListDisplay(&list);

	SeqListReverse_3(&list);
	printf("交换第三次后的序列：");
	ListDisplay(&list);

	return 0;
}

void InitSeqList(SeqList * list){
	list->elem=(ElemType*)malloc(list->size*sizeof(ElemType));
	if(list->elem==NULL) 
		exit(0);
	list->length=0;
	list->size=MAXSIZE;
}
void SeqListReverse_1(SeqList * list){
	ElemType temp;
	for(int i=0;i<(list->length)/2;i++){
		temp=list->elem[i];
		list->elem[i]=list->elem[list->length-i-1];
		list->elem[list->length-i-1]=temp;
	}
}
void SeqListReverse_2(SeqList * list){
	ElemType * p=&(list->elem[0]);
	ElemType * q=&(list->elem[list->length-1]);
	while(p<q){
		*p+=*q;
		*q=*p-*q;
		*p-=*q;
		p++;
		q--;
	}
}
void SeqListReverse_3(SeqList * list){
	int i=0,j=list->length-1;
	while(i<j){
		list->elem[i]+=list->elem[j];
		list->elem[j]=list->elem[i]-list->elem[j];
		list->elem[i]-=list->elem[j];
		i++;
		j--;
	}
}
void ListDisplay(SeqList * list){
	for(int i=0;i<list->length;i++){
		printf("%d",list->elem[i]);
	}
	printf("\n");
}